package com.zhangfb95.crosschain.plugin.container.java.fabric2.infra.config.configuration;

import com.zhangfb95.crosschain.infra.util.tls.server.JettyWebServerBuilder;
import com.zhangfb95.crosschain.infra.util.tls.server.WebServerSslProperties;
import com.zhangfb95.crosschain.plugin.container.java.fabric2.infra.config.properties.WebServerProperties;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.server.WebServer;
import org.springframework.boot.web.servlet.ServletContextInitializer;
import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
import org.springframework.stereotype.Component;

/**
 * 我的web服务器工厂
 *
 * @author zhangfubing
 * @since 2023/10/17
 */
@Slf4j
@Component
public class MyServletWebServerFactory implements ServletWebServerFactory {

    @Autowired
    private WebServerProperties webServerProperties;

    @Override
    public WebServer getWebServer(ServletContextInitializer... initializers) {
        WebServerSslProperties sslProperties = new WebServerSslProperties()
                .setPort(webServerProperties.getPort())
                .setSslType(webServerProperties.getSslType())
                .setCaCert(webServerProperties.getCaCert())
                .setSslKey(webServerProperties.getSslKey())
                .setSslCert(webServerProperties.getSslCert());
        return JettyWebServerBuilder.build(sslProperties, initializers);
    }
}
